home *** CD-ROM | disk | FTP | other *** search
/ Revista CD Expert 8 / Revista CD Expert nº 08 CD1.iso / Utilitarios / Programacao / Bloodshed Dev-C++ 2.0 / _SETUP.1 / va-sh.h < prev    next >
C/C++ Source or Header  |  1998-03-08  |  6KB  |  200 lines

  1. /* This is just like the default gvarargs.h
  2.    except for differences described below.  */
  3.  
  4. /* Define __gnuc_va_list.  */
  5.  
  6. #ifndef __GNUC_VA_LIST
  7. #define __GNUC_VA_LIST
  8.  
  9. #ifdef __SH3E__
  10.  
  11. typedef long __va_greg;
  12. typedef double __va_freg;
  13.  
  14. typedef struct {
  15.   __va_greg * __va_next_o;        /* next available register */
  16.   __va_greg * __va_next_o_limit;    /* past last available register */
  17.   __va_freg * __va_next_fp;        /* next available fp register */
  18.   __va_freg * __va_next_fp_limit;    /* last available fp register */
  19.   __va_greg * __va_next_stack;        /* next extended word on stack */
  20. } __gnuc_va_list;
  21.  
  22. #else /* ! SH3E */
  23.  
  24. typedef void *__gnuc_va_list;
  25.  
  26. #endif /* ! SH3E */
  27.  
  28. #endif /* __GNUC_VA_LIST */
  29.  
  30. /* If this is for internal libc use, don't define anything but
  31.    __gnuc_va_list.  */
  32. #if defined (_STDARG_H) || defined (_VARARGS_H)
  33.  
  34. #ifdef _STDARG_H
  35.  
  36. #ifdef __SH3E__
  37.  
  38. #define va_start(AP, LASTARG) \
  39. __extension__ \
  40.   ({ \
  41.      AP.__va_next_fp = (__va_freg *) __builtin_saveregs (); \
  42.      AP.__va_next_fp_limit = (AP.__va_next_fp + \
  43.                   (__builtin_args_info (1) < 8 ? 8 - __builtin_args_info (1) : 0)); \
  44.      AP.__va_next_o = (__va_greg *) AP.__va_next_fp_limit; \
  45.      AP.__va_next_o_limit = (AP.__va_next_o + \
  46.                  (__builtin_args_info (0) < 4 ? 4 - __builtin_args_info (0) : 0)); \
  47.      AP.__va_next_stack = (__va_greg *) __builtin_next_arg (LASTARG); \
  48.   })
  49.  
  50. #else /* ! SH3E */
  51.  
  52. #define va_start(AP, LASTARG)                         \
  53.  (AP = ((__gnuc_va_list) __builtin_next_arg (LASTARG)))
  54.  
  55. #endif /* ! SH3E */
  56.  
  57. #else /* _VARARGS_H */
  58.  
  59. #define va_alist  __builtin_va_alist
  60. #define va_dcl    int __builtin_va_alist;...
  61.  
  62. #ifdef __SH3E__
  63.  
  64. #define va_start(AP) \
  65. __extension__ \
  66.   ({ \
  67.      AP.__va_next_fp = (__va_freg *) __builtin_saveregs (); \
  68.      AP.__va_next_fp_limit = (AP.__va_next_fp + \
  69.                   (__builtin_args_info (1) < 8 ? 8 - __builtin_args_info (1) : 0)); \
  70.      AP.__va_next_o = (__va_greg *) AP.__va_next_fp_limit; \
  71.      AP.__va_next_o_limit = (AP.__va_next_o + \
  72.                  (__builtin_args_info (0) < 4 ? 4 - __builtin_args_info (0) : 0)); \
  73.      AP.__va_next_stack = (__va_greg *) __builtin_next_arg (__builtin_va_alist) \
  74.        - (__builtin_args_info (0) >= 4 || __builtin_args_info (1) >= 8 ? 1 : 0); \
  75.   })
  76.  
  77. #else /* ! SH3E */
  78.  
  79. #define va_start(AP)  AP=(char *) &__builtin_va_alist
  80.  
  81. #endif /* ! SH3E */
  82.  
  83. #endif /* _STDARG */
  84.  
  85. #ifndef va_end
  86. void va_end (__gnuc_va_list);        /* Defined in libgcc.a */
  87.  
  88. /* Values returned by __builtin_classify_type.  */
  89.  
  90. enum __va_type_classes {
  91.   __no_type_class = -1,
  92.   __void_type_class,
  93.   __integer_type_class,
  94.   __char_type_class,
  95.   __enumeral_type_class,
  96.   __boolean_type_class,
  97.   __pointer_type_class,
  98.   __reference_type_class,
  99.   __offset_type_class,
  100.   __real_type_class,
  101.   __complex_type_class,
  102.   __function_type_class,
  103.   __method_type_class,
  104.   __record_type_class,
  105.   __union_type_class,
  106.   __array_type_class,
  107.   __string_type_class,
  108.   __set_type_class,
  109.   __file_type_class,
  110.   __lang_type_class
  111. };
  112.  
  113. #endif
  114. #define va_end(pvar)    ((void)0)
  115.  
  116. #ifdef __LITTLE_ENDIAN__
  117. #define __LITTLE_ENDIAN_P 1
  118. #else
  119. #define __LITTLE_ENDIAN_P 0
  120. #endif
  121.  
  122. #define __SCALAR_TYPE(TYPE)                    \
  123.   ((TYPE) == __integer_type_class                \
  124.    || (TYPE) == __char_type_class                \
  125.    || (TYPE) == __enumeral_type_class)
  126.  
  127. /* RECORD_TYPE args passed using the C calling convention are
  128.    passed by invisible reference.  ??? RECORD_TYPE args passed
  129.    in the stack are made to be word-aligned; for an aggregate that is
  130.    not word-aligned, we advance the pointer to the first non-reg slot.  */
  131.  
  132.   /* When this is a smaller-than-int integer, using
  133.      auto-increment in the promoted (SImode) is fastest;
  134.      however, there is no way to express that is C.  Therefore,
  135.      we use an asm.
  136.      We want the MEM_IN_STRUCT_P bit set in the emitted RTL, therefore we
  137.      use unions even when it would otherwise be unnecessary.  */
  138.  
  139. #define __va_arg_sh1(AP, TYPE) __extension__                 \
  140. __extension__                                \
  141. ({(sizeof (TYPE) == 1                            \
  142.    ? ({union {TYPE t; char c;} __t;                    \
  143.        asm(""                                \
  144.        : "=r" (__t.c)                        \
  145.        : "0" ((((union { int i, j; } *) (AP))++)->i));        \
  146.        __t.t;})                                \
  147.    : sizeof (TYPE) == 2                            \
  148.    ? ({union {TYPE t; short s;} __t;                    \
  149.        asm(""                                \
  150.        : "=r" (__t.s)                        \
  151.        : "0" ((((union { int i, j; } *) (AP))++)->i));        \
  152.        __t.t;})                                \
  153.    : sizeof (TYPE) >= 4 || __LITTLE_ENDIAN_P                \
  154.    ? (((union { TYPE t; int i;} *) (AP))++)->t                \
  155.    : ((union {TYPE t;TYPE u;}*) ((char *)++(int *)(AP) - sizeof (TYPE)))->t);})
  156.  
  157. #ifdef __SH3E__
  158.  
  159. #define __PASS_AS_FLOAT(TYPE_CLASS,SIZE) \
  160.   (TYPE_CLASS == __real_type_class && SIZE == 4)
  161.  
  162. #define va_arg(pvar,TYPE)                    \
  163. __extension__                            \
  164. ({int __type = __builtin_classify_type (* (TYPE *) 0);        \
  165.   void * __result_p;                        \
  166.   if (__PASS_AS_FLOAT (__type, sizeof(TYPE)))            \
  167.     {                                \
  168.       if (pvar.__va_next_fp < pvar.__va_next_fp_limit)        \
  169.     {                            \
  170.       __result_p = &pvar.__va_next_fp;            \
  171.     }                            \
  172.       else                            \
  173.     __result_p = &pvar.__va_next_stack;            \
  174.     }                                \
  175.   else                                \
  176.     {                                \
  177.       if (pvar.__va_next_o + ((sizeof (TYPE) + 3) / 4)        \
  178.       <= pvar.__va_next_o_limit)                 \
  179.     __result_p = &pvar.__va_next_o;                \
  180.       else                            \
  181.     {                            \
  182.       if (sizeof (TYPE) > 4)                \
  183.         pvar.__va_next_o = pvar.__va_next_o_limit;        \
  184.                                 \
  185.       __result_p = &pvar.__va_next_stack;            \
  186.     }                            \
  187.     }                                 \
  188.   __va_arg_sh1(*(void **)__result_p, TYPE);})
  189.  
  190. #else /* ! SH3E */
  191.  
  192. #define va_arg(AP, TYPE) __va_arg_sh1((AP), TYPE)
  193.  
  194. #endif /* SH3E */
  195.  
  196. /* Copy __gnuc_va_list into another variable of this type.  */
  197. #define __va_copy(dest, src) (dest) = (src)
  198.  
  199. #endif /* defined (_STDARG_H) || defined (_VARARGS_H) */
  200.